﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using InkFx.WinControl.Core;
using InkFx.WinControl.Design;

namespace InkFx.WinControl
{
    /// <summary>
    /// 用于对控件集合进行分组。
    /// </summary>
    //[Designer(typeof(SimpPanelDesigner))]
    [ToolboxItem(false), Docking(DockingBehavior.Never)]
    //[TechSupport("http://ink-fx.com/SDK/InkFx.WinControl/SimpPanel/")]
    public class SimpPanel : System.Windows.Forms.Panel
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public SimpPanel()
        {
            SetStyle(Win32API.ControlStylesUAORSD, true);

            //base.BackColor = Color.Transparent;
        }

        #region  注 销 属 性

        /// <summary>
        /// 获取或设置控件的背景色。
        /// </summary>
        public override Color BackColor
        {
            get { return base.BackColor; }
            set { var color = base.BackColor; /*if (value.A < 255) { value = Color.FromArgb(255, value.R, value.G, value.B); }*/ if (color.A != value.A || color.R != value.R || color.G != value.G || color.B != value.B) { base.BackColor = value; this.Invalidate(); } } 
        }

        /// <summary>
        /// 获取或设置一个值，该值指示容器是否允许用户滚动到任何放置在其可见边界之外的控件。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool AutoScroll
        {
            get { return base.AutoScroll; }
            set { base.AutoScroll = value; }
        }
        /// <summary>
        /// 获取或设置自动滚动边距的大小。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new Size AutoScrollMargin
        {
            get { return base.AutoScrollMargin; }
            set { base.AutoScrollMargin = value; }
        }
        /// <summary>
        /// 获取或设置自动滚动的最小尺寸。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new Size AutoScrollMinSize
        {
            get { return base.AutoScrollMinSize; }
            set { base.AutoScrollMinSize = value; }
        }
        /// <summary>
        /// 获取或设置一个值，该值指示控件是否可以接受用户拖放到它上面的数据。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool AllowDrop
        {
            get { return base.AllowDrop; }
            set { base.AllowDrop = value; }
        }

        /// <summary>
        /// 获取或设置辅助功能客户端应用程序所使用的控件名称。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new string AccessibleName
        {
            get { return base.AccessibleName; }
            set { base.AccessibleName = value; }
        }
        /// <summary>
        /// 获取或设置辅助功能客户端应用程序使用的控件说明。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new string AccessibleDescription
        {
            get { return base.AccessibleDescription; }
            set { base.AccessibleDescription = value; }
        }
        /// <summary>
        /// 获取或设置控件的辅助性角色
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new AccessibleRole AccessibleRole
        {
            get { return base.AccessibleRole; }
            set { base.AccessibleRole = value; }
        }

        /// <summary>
        /// 为该控件获取数据绑定。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new ControlBindingsCollection DataBindings
        {
            get { return base.DataBindings; }
        }

        /// <summary>
        /// 获取或设置与此控件关联的 System.Windows.Forms.ContextMenuStrip。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new System.Windows.Forms.ContextMenuStrip ContextMenuStrip
        {
            get { return base.ContextMenuStrip; }
            set { base.ContextMenuStrip = value; }
        }
        /// <summary>
        /// 获取或设置一个值，该值指示控件是否可以对用户交互作出响应。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool Enabled
        {
            get { return base.Enabled; }
            set { base.Enabled = value; }
        }
        /// <summary>
        /// 获取或设置控件的输入法编辑器 (IME) 模式。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new ImeMode ImeMode
        {
            get { return base.ImeMode; }
            set { base.ImeMode = value; }
        }
        /// <summary>
        /// 获取或设置一个值，该值指示控件是否会引起在任何需要在接收焦点时执行验证的控件上执行验证。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool CausesValidation
        {
            get { return base.CausesValidation; }
            set { base.CausesValidation = value; }
        }

        /// <summary>
        /// 此属性与此类无关。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool AutoSize
        {
            get { return base.AutoSize; }
            set { base.AutoSize = value; }
        }
        /// <summary>
        /// 指示控件的自动调整大小行为。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new AutoSizeMode AutoSizeMode
        {
            get { return base.AutoSizeMode; }
            set { base.AutoSizeMode = value; }
        }
        /// <summary>
        /// 获取或设置控件绑定到的容器的边缘并确定控件如何随其父级一起调整大小。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new AnchorStyles Anchor
        {
            get { return base.Anchor; }
            set { base.Anchor = value; }
        }
        /// <summary>
        /// 指示控件的边框样式。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new BorderStyle BorderStyle
        {
            get { return base.BorderStyle; }
            set { base.BorderStyle = value; }
        }
        /// <summary>
        /// 获取或设置哪些控件边框停靠到其父控件并确定控件如何随其父级一起调整大小。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new DockStyle Dock
        {
            get { return base.Dock; }
            set { base.Dock = value; }
        }
        /// <summary>
        /// 获取控件的所有边缘的停靠边距设置。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new ScrollableControl.DockPaddingEdges DockPadding
        {
            get { return base.DockPadding; }
        }
        /// <summary>
        /// 获取或设置控件的高度。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new int Height
        {
            get { return base.Height; }
            set { base.Height = value; }
        }
        /// <summary>
        /// 获取或设置该控件的左上角相对于其容器的左上角的坐标。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new Point Location
        {
            get { return base.Location; }
            set { base.Location = value; }
        }
        /// <summary>
        /// 获取控件之间默认情况下指定的间距（以像素为单位）。
        /// </summary>
        protected override Padding DefaultMargin
        {
            get { return new Padding(0, 0, 0, 0); }
        }
        /// <summary>
        /// 获取或设置大小，该大小是 System.Windows.Forms.Control.GetPreferredSize(System.Drawing.Size) 可以指定的下限。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new Size MinimumSize
        {
            get { return base.MinimumSize; }
            set { base.MinimumSize = value; }
        }
        /// <summary>
        /// 获取或设置大小，该大小是 System.Windows.Forms.Control.GetPreferredSize(System.Drawing.Size) 可以指定的上限。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new Size MaximumSize
        {
            get { return base.MaximumSize; }
            set { base.MaximumSize = value; }
        }

        /// <summary>
        /// 获取或设置控件之间的空间。
        /// </summary>
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new Padding Margin
        {
            get { return base.Margin; }
            set { base.Margin = value; }
        }
        /// <summary>
        /// 获取或设置控件内的空白。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new Padding Padding
        {
            get { return base.Padding; }
            set { base.Padding = value; }
        }

        /// <summary>
        /// 获取或设置控件的名称。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new string Name
        {
            get { return base.Name; }
            set { base.Name = value; }
        }
        /// <summary>
        /// 获取或设置控件的父容器。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new System.Windows.Forms.Control Parent
        {
            get { return base.Parent; }
            set { base.Parent = value; }
        }
        /// <summary>
        /// 获取或设置控件的高度和宽度。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new Size Size
        {
            get { return base.Size; }
            set { base.Size = value; }
        }
        /// <summary>
        /// 获取或设置在控件的容器的控件的 Tab 键顺序。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new int TabIndex
        {
            get { return base.TabIndex; }
            set { base.TabIndex = value; }
        }
        /// <summary>
        /// 获取或设置一个值，该值指示用户能否使用 Tab 键将焦点放到该控件上。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool TabStop
        {
            get { return base.TabStop; }
            set { base.TabStop = value; }
        }
        /// <summary>
        /// 获取或设置一个值，该值指示是否显示该控件及其所有子控件。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new bool Visible
        {
            get { return base.Visible; }
            set { base.Visible = value; }
        }
        /// <summary>
        /// 获取或设置控件的宽度。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new int Width
        {
            get { return base.Width; }
            set { base.Width = value; }
        }

        #endregion


        #region  注 销 事 件

        /// <summary>
        /// 在 System.Windows.Forms.Panel.AutoSize 属性的值更改后发生。
        /// </summary>
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler AutoSizeChanged
        {
            add { base.AutoSizeChanged += value; }
            remove { base.AutoSizeChanged -= value; }
        }
        /// <summary>
        /// 在 System.Windows.Forms.Control.Visible 属性值更改时发生。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler VisibleChanged
        {
            add { base.VisibleChanged += value; }
            remove { base.VisibleChanged -= value; }
        }
        /// <summary>
        /// 当 System.Windows.Forms.Control.Dock 属性的值更改时发生。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler DockChanged
        {
            add { base.DockChanged += value; }
            remove { base.DockChanged -= value; }
        }
        /// <summary>
        /// 在 System.Windows.Forms.Control.Location 属性值更改后发生。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler LocationChanged
        {
            add { base.LocationChanged += value; }
            remove { base.LocationChanged -= value; }
        }
        /// <summary>
        /// 在 System.Windows.Forms.Control.TabIndex 属性值更改时发生。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TabIndexChanged
        {
            add { base.TabIndexChanged += value; }
            remove { base.TabIndexChanged -= value; }
        }
        /// <summary>
        /// 在 System.Windows.Forms.Control.TabStop 属性值更改时发生。
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TabStopChanged
        {
            add { base.TabStopChanged += value; }
            remove { base.TabStopChanged -= value; }
        }


        #endregion


        /// <summary>
        /// 引发 System.Windows.Forms.Control.SizeChanged 事件。
        /// </summary>
        /// <param name="e">包含事件数据的 System.EventArgs。</param>
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            this.Invalidate();
        }
        /// <summary>
        /// 延迟触发 base.Invalidate() 函数
        /// </summary>
        public virtual void Invalidate()
        {
            //GUIHelper.Invalidate(this);
        }




        /// <summary>
        /// 内部字段
        /// </summary>
        protected static readonly object m_EventSize2Changed = new object();
        /// <summary>
        /// 窗体尺寸改变后 延迟发生
        /// </summary>
        [CategorySkinTheme]
        public event EventHandler Size2Changed
        {
            add { base.Events.AddHandler(m_EventSize2Changed, value); }
            remove { base.Events.RemoveHandler(m_EventSize2Changed, value); }
        }
        /// <summary>
        /// 窗体尺寸改变后 延迟发生
        /// </summary>
        /// <param name="e">Type: EventArgs</param>
        public virtual void OnSize2Changed(EventArgs e)
        {
            var level = Win32API.GetParentLevel(this);
            if (level >= 16) { Win32API.ReSetWindowPos(this.Handle); }
            EventHandler handler = base.Events[m_EventSize2Changed] as EventHandler;
            if (handler != null) handler(this, e);
            this.Invalidate(); //if (level >= 16) { this.Invalidate(); }
        }
    }




}


namespace InkFx.WinControl.Design
{
    //public class SimpPanelDesigner : TechSupportSizeScrollableControlDesigner
    //{
    //    private SimpPanelActionList m_ActionList;
    //    public override DesignerActionListCollection ActionLists
    //    {
    //        get
    //        {
    //            if (m_ActionList == null)
    //                m_ActionList = new SimpPanelActionList(this.Component);

    //            DesignerActionListCollection listAction = new DesignerActionListCollection(); //base.ActionLists;
    //            if (!listAction.Contains(m_ActionList))
    //                listAction.Add(m_ActionList);
    //            return listAction;
    //        }
    //    }
    //    public override SelectionRules SelectionRules
    //    {
    //        get
    //        {
    //            //return SelectionRules.Locked;
    //            //SelectionRules selectionRules = base.SelectionRules;
    //            ////object component = base.Component;
    //            //selectionRules &= ~(SelectionRules.AllSizeable);
    //            //return selectionRules;

    //            SelectionRules result = SelectionRules.None;
    //            //System.Windows.Forms.Control control = this.Control;
    //            //if (control.Parent is SimpPanel)
    //            //{
    //            //    result = SelectionRules.Locked;
    //            //}
    //            return result;
    //        }
    //    }

    //    public class SimpPanelActionList : DesignerActionList
    //    {
    //        private SimpPanel control;
    //        public SimpPanelActionList(IComponent component) : base(component)
    //        {
    //            this.control = component as SimpPanel;
    //        }

    //        public override DesignerActionItemCollection GetSortedActionItems()
    //        {
    //            DesignerActionItemCollection items = new DesignerActionItemCollection();
    //            //items.Add(new DesignerActionMethodTagItem(this, "Select", "全部隐藏", "NULL"));
    //            return items;
    //        }

    //        public void Select(object tag)
    //        {
    //            ////MessageBox.ShowInfo("Select: " + tag);

    //            //if (tag + "" == "NULL")
    //            //    control.Select(null);
    //            //else
    //            //{
    //            //    System.Windows.Forms.Control ctrl = tag as System.Windows.Forms.Control;
    //            //    if (control == null || control.Disposing || control.IsDisposed) return;
    //            //    if (ctrl == null || !control.Contains(ctrl)) return;
    //            //    control.Select(ctrl);
    //            //}

    //            //CreateCode();
    //        }

    //        private void CreateCode()
    //        {
    //            ////var designerHost = (IDesignerHost)this.Component.Site.GetService(typeof(IDesignerHost));
    //            ////var designer = (MultiPanelDesigner)designerHost.GetDesigner(this.control);

    //            //PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(this.Component)["SelectedControl"];
    //            //if (propertyDescriptor != null && this.control != null)
    //            //    propertyDescriptor.SetValue(this.Component, this.control.SelectedControl);
    //        }
    //    }
    //}
}
